import json

import requests


if __name__ == '__main__':

    # url = 'https://m.douban.com/rexxar/api/v2/movie/recommend?refresh=0&start=0&count=20&selected_categories=%7B%7D&uncollect=false&tags=%E5%8A%B1%E5%BF%97'
    url = 'https://m.douban.com/rexxar/api/v2/movie/recommend'
    params = dict(
        refresh=0,
        start=0,
        count=20,
        selected_categories={},
        uncollect=False,
        tags='励志',
    )


    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 SE 2.X MetaSr 1.0',
        'Referer': 'https://movie.douban.com/explore'
    }



    resp = requests.get(url, params=params,headers=headers)
    print(resp.json())


    with open('douban.json', 'w', encoding='utf-8') as f:
        f.write(json.dumps(resp.json(), ensure_ascii=False))  # 不适用ASCII,可正常显示中文


